﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace NAccounting.Models
{
    public class LotDetailModel
    {
        public int Id { get; set; }
        public bool CanSave { get; set; }
        public bool CanSaveAndOpenLote { get; set; }
        public bool CanCloseLote { get; set; }
        public bool CanCreateAccountingEntry { get; set; }
        public bool SaveAndOpenLote { get; set; }
        public bool IsBalanced { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "Descrição é de preenchimento obrigatório.", MinimumLength = 6)]
        [Display(Name = "Descrição: ")]
        public string Description { get; set; }

        [Display(Name = "Data de Abertura: ")]
        public string OpenDate { get; set; }

        [Display(Name = "Data de Fechamento: ")]
        public string CloseDate { get; set; }

        [Display(Name = "Crédito: ")]
        public string TotalCredit { get; set; }

        [Display(Name = "Débito: ")]
        public string TotalDebit { get; set; }

        [Required]
        [Display(Name = "Início: ")]
        public string PeriodStart { get; set; }
        public string PeriodStartJs { get; set; }

        [Required]
        [Display(Name = "Fim: ")]
        public string PeriodEnd { get; set; }
        public string PeriodEndJs { get; set; }

        public bool HasReleases { get; set; }

        public bool HasPeriod
        {
            get { return !String.IsNullOrWhiteSpace(PeriodStart) || !String.IsNullOrWhiteSpace(PeriodEnd); }
        }

        public bool HasOpenDate { get; set; }
        public bool HasCloseDate { get; set; }

        public LotDetailModel()
        { 
        }
    }

    public class LotListModel
    {
        [Display(Name = "Selecione o Estado:")]
        public SelectList LotState { get; set; }

        public SelectList DateOptions { get; set; }

        [Display(Name = "Selecione a período:")]
        public string SelectedDateOption { get; set; }

        public LotListModel()
        {
            SelectedDateOption = FilterDateOptionsEnum.ThisMonth.ToString();
            DateOptions = new SelectList(new FilterDateOptions().Options, "Key", "Text");
            LotState = new SelectList(new Dictionary<string, string>() 
                {
                    {"Todos", "A"},
                    {"Somente os Abertos", "O"},
                    {"Somente os Fechados", "F"},
                }, "Value", "Key", "A");
        }
    }

    public class ClosePeriodsModel
    {
        public ClosePeriodsModel()
        {
            LotsByDate = new List<BalancedLotByDate>();
        }

        public List<BalancedLotByDate> LotsByDate { get; set; }

        public class BalancedLotByDate
        {
            public string Date { get; set; }
            public IEnumerable<BalancedLotDetail> Lots { get; set; }
        }

        public class BalancedLotDetail
        {
            public int Id { get; set; }
            public string Description { get; set; }
            public string Value { get; set; }
            public string DivergenceType { get; set; }
        }
    }
}